package order.service;

import com.example.utils.Message;
import org.springframework.stereotype.Service;

@Service
public class OrderManageService {

    public Message confirm(Message paymentMss, Message carrierMss) {
        Message m = new Message(paymentMss.getOrderId(),
                paymentMss.getStatus(),
                "ORDERS");
        if (paymentMss.getStatus().equals("ACCEPT") &&
                carrierMss.getStatus().equals("ACCEPT")) {
            m.setStatus("SUCCESS");
        } else if (paymentMss.getStatus().equals("REJECT") &&
                carrierMss.getStatus().equals("REJECT")) {
            m.setStatus("FAIL");
        } else if (paymentMss.getStatus().equals("REJECT") ||
                carrierMss.getStatus().equals("REJECT")) {
            String source = paymentMss.getStatus().equals("REJECT")
                    ? "payment" : "carrier";
            m.setStatus("ROLLBACK");
            m.setSource(source);
        }
        return m;
    }

}
